package br.com.gsh.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.gsh.pojo.Twitter;
import br.com.gsh.service.TwitterService;

public class RespostaTwittaServlet extends HttpServlet{

	private static final long serialVersionUID = -154340731751042775L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String nick = request.getParameter("nick");
		String idTuiter = request.getParameter("idTuiter");
		String respTwitter = request.getParameter("respTuitter");
		
		System.out.println(respTwitter);
		
		String resposta = "..." + nick + " respondeu: " + respTwitter;
		
		TwitterService service = new TwitterService();
//		Twitter twit = new Twitter();
		Twitter twit2 = new Twitter();

//		twit.setMensagem(respTwitter);
//		twit.setIdUsuario(nick);
//		twit.setPergunta(idTuiter);
		
		twit2.setResposta(resposta);
		twit2.setId(Integer.parseInt(idTuiter));
	
		try {
//			service.adiciona(twit);
			service.atualizaResp(twit2);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		response.sendRedirect("/Twitter/listTwitterUserServlet");
		
	}

}


